package com.itjob.deep.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CharseterEncodingFilter extends BaseFilter {

	@Override
	public void doBaseFilter(FilterConfig config,
			HttpServletRequest httpRequest, HttpServletResponse httpRespone,
			FilterChain chain) throws IOException, ServletException {
		String charset = config.getInitParameter("charset");
		charset = charset == null ? "UTF-8" : charset;

		httpRequest.setCharacterEncoding(charset);

		chain.doFilter(httpRequest, httpRespone);

		httpRespone.setCharacterEncoding(charset);
		httpRespone.setContentType("text/html; charset=" + charset);

	}
}
